import { Body, Controller, Get, Post, UseFilters, UseGuards, UseInterceptors } from '@nestjs/common'
import { jwtGuard } from '../guards/jwt.guard'
import { AdminGuard } from '../guards/admin.guard'
import { IsNotEmpty, IsString } from 'class-validator'
import { Exclude, Expose } from 'class-transformer'
// import { SerializeInterceptor } from '../interceptors/serialize/serialize.interceptor'
import { Serialize } from '../decorators/serialize.decorator'
import { CaslGuard } from '../guards/casl.guard'
import { Can, Cannot, CheckPolicies } from '../decorators/casl.decorator'
import { Action } from '../enum/casl.enum'
import { Logs } from './logs.entity'
import { TypeormFilter } from '../filters/typeorm.filter'

class logDto {
  @IsString()
  id?: string

  @IsString()
  @IsNotEmpty()
  msg: string
}
class PublicLogsDto {
  @Expose()
  msg: string
  @Exclude()
  id: string
}

@Controller('logs')
@UseFilters(TypeormFilter)
@UseGuards(jwtGuard, CaslGuard)
@CheckPolicies((ability) => ability.can(Action.Read, Logs))
@Can(Action.Read, Logs)
export class LogsController {
  @Get()
  @Can(Action.Update, Logs)
  getTest() {
    return 'test'
  }
  @Post()
  // @UseInterceptors(new SerializeInterceptor(PublicLogsDto))
  @Serialize(PublicLogsDto)
  postTest(@Body() dto: logDto) {
    console.log('🚀 ~ LogsController ~ postTest ~ dto:', dto)
    return dto
  }
}
